﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace uban.demo.Protocol
{
    public class Message
    {
        // 验证板绑定学生的结果 服务器==>数位板
        //-------------------------------------------------------------
        public readonly static byte[] g_cmd_bind_success = new byte[14] { 0x80, 0x90, 0x06, 0x00, 0x00, 0x00, 0x88, 0x00, 0x01, 0x00, 0x04, 0x00, 0x0D, 0x0A };
        public readonly static byte[] g_cmd_bind_failed = new byte[14] { 0x80, 0x90, 0x06, 0x00, 0x00, 0x00, 0x88, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0D, 0x0A };
        //-------------------------------------------------------------

        // 心跳	
        //-------------------------------------------------------------
        public readonly static byte[] g_cmd_tablet_heart = new byte[6] { 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 };
        public readonly static byte[] g_cmd_server_heart = new byte[8] { 0x80, 0x10, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x0A };
        public static MsgType GetInfoType(byte first, byte second)
        {
            /* 上线通知 */
            if (first == 0xA5 && second == 0X90)
                return MsgType.InfoType_Online;

            /* 心跳包 */
            if (first == g_cmd_tablet_heart[0] && second == g_cmd_tablet_heart[1])
                return MsgType.InfoType_Heart;

            /* 数据 */
            if (first == 0x80)
            {
                /* 笔数据 */
                if (second == 0x80 || second == 0x81 || second == 0x88)
                    return MsgType.InfoType_Pen;

                /* 设备按键 */
                if (second == 0x84)
                    return MsgType.InfoType_Tablet_Key;

                /* 鼠标按键 */
                if (second == 0x82)
                    return MsgType.InfoType_Mouse_Key;
            }

            return MsgType.InfoType_None;
        }
    }
    public enum MsgType
    {
        InfoType_None = -1,
        InfoType_Pen = 0,               // 笔数据
        InfoType_Online,            // 上线消息
        InfoType_Tablet_Key,        // 设备按键
        InfoType_Mouse_Key,         // 鼠标按键
        InfoType_Heart,             // 心跳包
    }
}
